<template>
    <section class="cadre">
            <el-form v-loading="formLoad" class="demo-form-inline  common-textarea CadreForm" ref="reviewForm" :model="reviewForm" label-width="240px" >
                        <el-form-item label="党建系统组织生活任务完成率" prop="partyActivityFinishRatio" :rules="{required: true, message: '党建系统组织生活任务完成率', trigger: 'blur'}" style="">
                            <el-input type="text" v-model="reviewForm.partyActivityFinishRatio" :rows="1" :disabled="!disabled"></el-input>
                        </el-form-item>
                        <el-form-item label="村干部员额数量" prop="cadrePosts" :rules="{required: true, message: '村干部员额数量', trigger: 'blur'}">
                            <el-input type="text" :rows="2"  v-model="reviewForm.cadrePosts" :disabled="!disabled"></el-input>
                        </el-form-item>
                        <el-form-item label="挂牌清理完成率" prop="cleanFinishRatio" :rules="{required: true, message: '挂牌清理完成率', trigger: 'blur'}">
                            <el-input type="text" :rows="2"  v-model="reviewForm.cleanFinishRatio" :disabled="!disabled"></el-input>
                        </el-form-item>
                        <el-form-item label="村干部35周岁以下" prop="cadreBelowThirtyFive" :rules="{required: true, message: '村干部35周岁以下', trigger: 'blur'}">
                            <el-input type="text" :rows="2"  v-model="reviewForm.cadreBelowThirtyFive" :disabled="!disabled"></el-input>
                        </el-form-item>
                        <el-form-item label="村干部35周岁到50周岁" prop="cadreBetweenThirtyFiveToFifty" :rules="{required: true, message: '村干部35周岁到50周岁', trigger: 'blur'}" style="">
                            <el-input type="text" v-model="reviewForm.cadreBetweenThirtyFiveToFifty" :rows="1" :disabled="!disabled"></el-input>
                        </el-form-item>
                        <el-form-item label="村干部超过50周岁" prop="cadreOverFifty" :rules="{required: true, message: '村干部超过50周岁', trigger: 'blur'}">
                            <el-input type="text" :rows="2"  v-model="reviewForm.cadreOverFifty" :disabled="!disabled"></el-input>
                        </el-form-item>
                        <el-form-item v-for="item in gradeForm" :label="item.quotaName">
                            <el-input type="text" :rows="2"  v-model="item.score" :disabled="!disabled"></el-input>
                        </el-form-item>
                        <div style="text-align: center" v-if="disabled">
                            <el-button  type="primary"  @click="save()">保存</el-button>
                        </div>
            </el-form>
    </section>
</template>

<script>
    export default {
        name: "Cadre",
        props:{
            currentTask:{
                type:Object,
            },
            currentCun:{
                type:String,
            },
            currentStatus:{
                type:Object
            }
        },
        data(){
            return{
                reviewForm : {},
                gradeForm : [],
                formLoad : false,
                disabled:false,
            }
        },
        watch:{
            'currentCun':{
                handler:function(){
                    this.getTargetDetail(this.currentCun);
                }
            },
            'currentStatus':{
                handler:function(){
                    this.disabled = this.currentTask.hasCheckTask&&this.currentStatus.status==0;
                }
            },
            'currentTask':{
                handler:function(){
                    this.disabled = this.currentTask.hasCheckTask&&this.currentStatus.status==0;
                }
            }

        },
        mounted() {
        },
        methods:{
            getTargetDetail(districtId){
                this.formLoad = true;
                this.$http('POST',`identity/detectionIndex/list`,{taskId:this.currentTask.taskId,districtId: districtId},false).then(data=>{
                    this.reviewForm = data[0];
                    this.$http('get',`identity/kPITownQuota/getAllByVillageId/${this.currentCun}/0302`,false).then(data=>{
                        this.gradeForm = data;
                        this.formLoad = false;
                    }).catch(()=>{
                        this.formLoad = false;
                    });
                }).catch(()=>{
                    this.formLoad = false;
                });
            },
            save(){
                this.formLoad = true;
                this.$http('PUT',`identity/detectionIndex/${this.reviewForm.id}id`,this.reviewForm,false).then(data=>{
                    this.$http('post',`identity//kPITownQuota/updateStatisticsQoutaScore`,this.gradeForm,false).then(data=>{
                        this.formLoad = false;
                        this.$message({
                            type : 'success',
                            message : '保存成功!'
                        })
                    }).catch(()=>{
                        this.formLoad = false;
                    });
                }).catch(()=>{
                    this.formLoad = false;
                });

            }
        }
    }

</script>

<style>

    .save {
        margin-bottom: 40px
    }
</style>

<style scoped>
    .cadre .CadreForm {
        width: 600px!important;
        text-align: left;
    }
</style>
